﻿using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Data.SqlClient;
using yunbo.Model.SM;
using Dapper;

namespace yunbo.Repositorys.SMRepositorys
{
    public class WLDBMXRepository
    {
        public string data = "Data Source=121.37.93.71;Initial Catalog=FanXingMES;User ID=sa;Password=geili@2025;";
        public int Postwldbmx(wldbmx wldbmx)
        {
            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $"insert into wms_wldbmx(wldbmx_code,wldb_code,wl_code,wldbmx_wlmc,wldbmx_wllx,wldbmx_ggxh,wldbmx_sqdbsl,kc_code)\r\n" +
                    $"values('{wldbmx.wldbmx_code}','{wldbmx.wldb_code}','{wldbmx.wl_code}','{wldbmx.wldbmx_wlmc}','{wldbmx.wldbmx_wllx}','{wldbmx.wldbmx_ggxh}',{wldbmx.wldbmx_sqdbsl},'{wldbmx.kc_code}')";
                int rs = connection.Execute(sql);
                return rs;
            }
        }
        public List<wldbmx> Getwldbmx(string code)
        {

            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $"select a.kc_code,c.kc_id,a.wl_code,a.wldbmx_id,a.wldbmx_code,a.wldb_code,a.wldbmx_wlmc,a.wldbmx_wllx,a.wldbmx_ggxh,a.wldbmx_sqdbsl,c.kc_sl,c.kc_jhsl,a.wldbmx_sqdbsl as wldbmx_ysqsl from wms_wldbmx a\r\ninner join [dbo].[wms_wldb] b on a.wldb_code=b.wldb_code\r\ninner join [dbo].[wms_kc] c on b.ckw_code=c.ck_code and a.wl_code=c.wl_code where a.wldb_code='{code}'";
                List<wldbmx> wldbmxs = connection.Query<wldbmx>(sql).ToList();
                return wldbmxs;
            }
        }
        public int Updatewldbmx(string code,int sl)
        {

            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $"update [dbo].[wms_wldbmx] set [wldbmx_sqdbsl]={sl} where [wldbmx_code]='{code}'";
                int rs = connection.Execute(sql);
                return rs;
            }
        }
        public int Deletewldbmx(string code)
        {

            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $"delete wms_wldbmx where wldbmx_code='{code}'";
                int rs = connection.Execute(sql);
                return rs;
            }
        }
    }
}
